<?
	if (isset($_GET['monthno'])) $monthno = $_GET['monthno'];
	if (isset($_GET['year'])) $year = $_GET['year'];
	if (!isset($monthno)) 
	{
		$monthno=date(n);
	}
	if (!isset($year)) 
	{
		$year = date(Y);
	}

	$monthfulltext = date(F, mktime(0, 0, 0, $monthno, 1, $year));
	$monthshorttext = date(M, mktime(0, 0, 0, $monthno, 1, $year));

	$day_in_mth = date(t, mktime(0, 0, 0, $monthno, 1, $year)) ;
	$day_text = date(D, mktime(0, 0, 0, $monthno, 1, $year));
?>
<style type="text/css">
.tdday { font-family: Verdana, Arial, Helvetica, sans-serif;
                  background-color: #1863B0;
                  font-weight: normal;
                  font-size: 9px;
                  width: 26px;
                  line-height: 20px;
                  color: #ffffff;
                  vertical-align: middle;
                  text-align: center;
				  text-decoration:none;
}
.tdtoday { font-family: Verdana, Arial, Helvetica, sans-serif;
				  background-color: #FF0000;
				  font-weight: bold;
                  font-size: 9px;
                  line-height: 16px;
                  width: 26px;
                  color: #FF0000;
                  vertical-align: middle;
                  text-align: center;
				  text-decoration:none;
}
.tdevent { font-family: Verdana, Arial, Helvetica, sans-serif;
                  background-color: #FF9900;
                  font-weight: bold;
                  font-size: 9px;
                  line-height: 16px;
                  width: 26px;
                  color: #003300;
                  vertical-align: middle;
                  text-align: center;
				  text-decoration:none;
}
.tdeventday { font-family: Verdana, Arial, Helvetica, sans-serif;
                  background-color: #FF9900;
                  font-weight: bold;
                  font-size: 9px;
                  line-height: 16px;
                  width: 26px;
                  color: #003300;
                  vertical-align: middle;
                  text-align: center;
				  text-decoration:none;
}
.tdheading { font-family: Verdana, Arial, Helvetica, sans-serif;
                  background-color: #1863B0;
                  font-weight: bold;
                  font-size: 9px;
                  line-height: 20px;
                  color: #ffffff;
                  vertical-align: middle;
                  text-align: center;
				  text-decoration:none;
}
.tddate { font-family: Verdana, Arial, Helvetica, sans-serif;
                  background-color: #C5C5C5;
                  font-weight: normal;
                  font-size: 9px;
                  line-height: 16px;
                  width: 26px;
                  color: #003300;
                  vertical-align: middle;
                  text-align: center;
				  text-decoration:none;
 }
.caltable { 
                   margin-bottom: 5px;
                   margin-top: 5px;
                   margin-right: 5px;
                   margin-left: 5px;
                   padding-top: 0px;
                   padding-right: 0px;
                   padding-bottom: 0px;
                   padding-left: 0px;
				   text-decoration:none;
}
</style>
<?
	$yb=$year;
	$yf=$year;
	$mb=$monthno-1;
	if ($mb<1) 
	{
		$mb=12; 
		$yb=$yb-1;
	}
	$mf=$monthno+1;
	if ($mf>12) 
	{
		$mf=1; 
		$yf=$yf+1;
	}
?>
<table class=caltable bgcolor="#999999" border="0" cellpadding="0" cellspacing="1px" width=94%>
<tr><td colspan=7 class=tdheading>
	<a title="prev month" href="<?php echo "index.php?monthno=$mb&year=$yb" ?>">&lt;&lt;</a>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size=1><? echo $monthshorttext." ".$year ?></font>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a title="next month" href="<?php echo "index.php?monthno=$mf&year=$yf" ?>">&gt;&gt;</a>
</td></tr>
<tr>
    <td class=tdday><font size="1">Mgg</font></td>
    <td class=tdday><font size="1">Snn</font></td>
    <td class=tdday><font size="1">Sls</font></td>
    <td class=tdday><font size="1">Rab</font></td>
    <td class=tdday><font size="1">Kms</font></td>
    <td class=tdday><font size="1">Jmt</font></td>
    <td class=tdday><font size="1">Sbt</font></td>
</tr>
<tr>
<?
$day_of_wk = date(w, mktime(0, 0, 0, $monthno, 1, $year));
if ($day_of_wk <> 0)
{
   for ($i=0; $i<$day_of_wk; $i++)
	{ 
	   echo "<td class=tddate>&nbsp;</td>"; 
	}
}
for ($date_of_mth = 1; $date_of_mth <= $day_in_mth; $date_of_mth++) 
{
	if ($day_of_wk = 0)
	{
		for ($i=0; $i<$day_of_wk; $i++);
		{ 
			echo "<tr>"; 
		}
	}
	$day_text = date(D, mktime(0, 0, 0, $monthno, $date_of_mth, $year));
	$date_no = date(d, mktime(0, 0, 0, $monthno, $date_of_mth, $year));
    $day_of_wk = date(w, mktime(0, 0, 0, $monthno, $date_of_mth, $year));
	$src=mysql_query("select * from event where event_tgl='".$year."-".$monthno."-".$date_no."'");
	$jml=mysql_num_rows($src);
	$ev=mysql_fetch_array($src);	
	if (($jml>0) && ( $date_no ==  date(j) &&  $monthno == date(n) ))
	{
		echo "<td bgcolor=".$ev["event_color"]."><a title=$date_no-$monthno-$year href=index.php?det=1&kd=keg&tgl_e=".$ev["event_id"]."><font color=#003300 size=1><strong>".$date_no."</strong></font></a></td>"; 
	} else
	if ($jml>0)
	{
		echo "<td bgcolor=".$ev["event_color"]."><a title=$date_no-$monthno-$year href=index.php?det=1&kd=keg&tgl_e=".$ev["event_id"]."><font color=#003300 size=1>".$date_no."</font></a></td>"; 
	} else 
	if ( $date_no ==  date(j) &&  $monthno == date(n) )
	{  
		echo "<td class=tdtoday><a title=$date_no-$monthno-$year><font color=#003300 size=1>".$date_no."</font></a></td>"; 
	} else {
		echo "<td class=tddate><a title=$date_no-$monthno-$year><font color=#003300 size=1>".$date_no."</a></td>";  
	}
	if ( $day_of_wk == 6 ) {  echo "</tr>"; }
	if ( $day_of_wk < 6 && $date_of_mth == $day_in_mth ) 
	{
		for ( $i = $day_of_wk ; $i < 6; $i++ ) 
		{
			echo "<td class=tddate>&nbsp;</td>"; 
		}
		echo "</tr>";
    }
 }
?>
</table>